//
//  CAnimationPlayW.mm
//  Cocos2DEditor
//
//  Created by waver on 10-6-21.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "CAnimationPlayW.h"
#import "CRoleCreate.h"


@implementation CAnimationPlayW

@synthesize __currentRole,__imageNameArray;


-(id)InitAction:(NSString*)fileName
{
	CRoleCreate * pInstance = CRoleCreate::Instance();
	__currentRole = pInstance->CreateOneRole([fileName UTF8String]);
	
	__fileName = [[NSString alloc]initWithString:fileName];
	
	__MainSprite = [CCSprite node];
	
	__SpriteArray = [NSMutableArray array];
	[self InitArray];
	
	return self;
}

-(void)InitArray
{
	if(nil == __imageNameArray)
	{
		__imageNameArray = [[NSMutableArray alloc] init];
	}
	else
	{
		[__imageNameArray release];
		__imageNameArray = [[NSMutableArray alloc] init];
	}
	
	if(nil == __FrameArray)
	{
		__FrameArray = [[NSMutableArray alloc] init];
	}
	else
	{
		[__FrameArray release];
		__FrameArray = [[NSMutableArray alloc] init];
	}
	
	if(nil == __timeArray)
	{
		__timeArray = [[NSMutableArray alloc] init];
	}
	else
	{
		[__timeArray release];
		__timeArray = [[NSMutableArray alloc] init];
	}
	
	vector<char*>& nameVec = ((Role*)__currentRole)->getImageName();
	
	//stroe the image name
	for(unsigned int i=0; i<nameVec.size();i++)
	{
		const char* nameP = nameVec[i];
		NSString * nameStr = [NSString stringWithUTF8String:nameP];
		[__imageNameArray addObject:nameStr];
	}
	[__imageNameArray retain];
}


-(void)dealloc
{
	[__fileName release];
	[super dealloc];
}



-(CActionSpriteW*)CreateActionSprite: (int)aniIndex doubleTime:(int)times  cyc:(BOOL)IsCys;
{
	CActionSpriteW * pSprite = [CActionSpriteW node];
	[pSprite InitChildSprite:aniIndex  Animation:self  cyc:IsCys];
	[pSprite SpeedUpPlay:times];
	
	return pSprite;
}

@end
